import { useEffect, useState } from "react";
import $http from "../utils/require";

export interface CategoryItem {
    name: string,
    _id: string,
    createAt?: string,
    updateAt?: string,
    __v?: number
}

const useCategories = (): [categories: CategoryItem[], setCategories: React.Dispatch<React.SetStateAction<CategoryItem[]>>] => {
    let [categories, setCategories] = useState<CategoryItem[]>([])
    useEffect(() => {
        $http['getCategories']().then(res => {
            setCategories(res)
        })
    }, [])

    return [categories, setCategories]
}
export default useCategories